package collection.stream;


import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

//
public class StreamApiDemo {
    public static void main(String[] args) {
        Random random = new Random();
        List<Integer> list = new ArrayList<>();
        for (int i=0;i<10;i++){
            list.add(random.nextInt(10));
        }
        System.out.println(list);
        List<Integer> list1 = list.stream().map(e->e*3).collect(Collectors.toList());
        System.out.println(list1);

        List<Integer> list2 = list.stream().filter(e->e%2==0).collect(Collectors.toList());

        System.out.println(list2);

        List<Integer> list3 = list.stream().distinct().collect(Collectors.toList());
        System.out.println(list3);

        List<Integer> list4 = list.stream().sorted((e1,e2)->e2-e1).collect(Collectors.toList());
        System.out.println(list4);

        List<Integer> list5 = list.stream()
                              .map(e->e*3)
                              .distinct()
                              .filter(e->e%2==0)
                              .sorted((e1,e2)->e2-e1)
                              .collect(Collectors.toList());

        System.out.println(list5);

    }
}
